﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AppFuscator
{
    enum AuthStatus
    {
        Ok,
        NotActive,
        NotFound,
        Unknown
    }

    enum AccountMode
    {
        Trial,
        AfterTrial,
        Full,
        Demo
    }

    enum UploadStatus
    {
        Ok,
        IniMaxSize,
        FormMaxSize,
        Partial,
        NoFile,
        Empty,
        NoTmpDir,
        CantWrite,
        Extension,
        NoFiles,
        WrongFile,
        Unknown,
        Removed
    }


    #region Converters

    class UploadStatusConverter
    {
        private static Dictionary<UploadStatus, string> statuses = new Dictionary<UploadStatus, string>();

        static UploadStatusConverter()
        {
            statuses.Add(UploadStatus.Ok, "No errors.");
            statuses.Add(UploadStatus.IniMaxSize, "Filesize of \"{0}\" is larger than filesize limit");
            statuses.Add(UploadStatus.FormMaxSize, "Filesize of \"{0}\" is larger than filesize limit.");
            statuses.Add(UploadStatus.Partial, "Partial upload of file: \"{0}\".");
            statuses.Add(UploadStatus.NoFile, "File \"{0}\" did not load to the server.");
            statuses.Add(UploadStatus.Empty, "File \"{0}\" is empty");
            statuses.Add(UploadStatus.NoTmpDir, "There is no temporary directory on server. Uploading of\"{0}\" cancelled.");
            statuses.Add(UploadStatus.CantWrite, "Can't write to disk. Uploading of \"{0}\" cancelled");
            statuses.Add(UploadStatus.Extension, "File \"{0}\" upload stopped by extension.");
            statuses.Add(UploadStatus.NoFiles, "Files array in not found try to update your program");
            statuses.Add(UploadStatus.WrongFile, "\"{0}\". Wrong file type/extension");
            statuses.Add(UploadStatus.Unknown, "\"{0}\". Unknown error.");
            statuses.Add(UploadStatus.Removed, "File: \"{0}\" not found on hardware.");
        }
        
        public static UploadStatus Convert(int num)
        {
            foreach (UploadStatus it in Enum.GetValues(typeof(UploadStatus)))
            {
                if (it.GetHashCode() == num)
                    return it;
            }

            throw new ArgumentOutOfRangeException();
        }

        public static int Convert(UploadStatus status)
        {
            return statuses.GetHashCode();
        }

        public static string ToString(UploadStatus status)
        {
            if(statuses[status] == null)
                throw new ArgumentOutOfRangeException();

            return statuses[status];
        }

        public static string ToString(int num)
        {
            return ToString(Convert(num));
        }
    }

    class AccountModeConverter
    {
        private static Dictionary<AccountMode, string> modes = new Dictionary<AccountMode, string>();
        static AccountModeConverter()
        {
            modes.Add(AccountMode.Trial, "trial");
            modes.Add(AccountMode.AfterTrial, "atrial");
            modes.Add(AccountMode.Full, "full");
            modes.Add(AccountMode.Demo, "demo");
        }

        public static AccountMode Convert(string state)
        {
            foreach (KeyValuePair<AccountMode, string> it in modes)
            {
                if (it.Value == state)
                    return it.Key;
            }

            throw new ArgumentOutOfRangeException();
        }

        public static string Convert(AccountMode mode)
        {
            return modes[mode];
        }
    }

    #endregion

    #region Exceptions

    class UploadException : Exception {
        public UploadException(string message) : base(message) { }
    };

    #endregion
}
